package socket;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 多线程tcp协议客户端 多个请求
 * */
public class ThreadPoolTcpServer {

    public static void main(String[] args) throws Exception {
        System.out.println("tcp服务端启动....");
        //新建服务端，指定端口
        ServerSocket serverSocket = new ServerSocket(8080);
        try{
            while (true){
                final Socket accept = serverSocket.accept();
                new Thread(new Runnable() {
                    public void run(){
                        try {
                            InputStream inputStream = accept.getInputStream();
                            inputStream = accept.getInputStream();
                            byte[] bytes = new byte[1024];
                            int len = inputStream.read(bytes);
                            String str = new String(bytes,0,len,"GBK");
                            System.out.println(str);
                            accept.getOutputStream().write("你好,欢迎访问没有响应码消息".getBytes());
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
            }
        }catch (Exception e){

        }finally {
            serverSocket.close();
        }
        System.out.println("tcp服务端关闭....");
    }
}
